<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021-03-19
 * Time: 11:38
 */

namespace app\http\middleware;


use think\facade\Cache;
use think\Request;

class CheckToken
{
    public function handle(Request $request,\Closure $next)
    {
        $token = $request->header('token');
        if (empty($token)) {
            return json(['code' => 404,'msg'=>'没有访问权限，请携带合法的token']);
        }

        if(Cache::get("token") !== $token){
            return json(['code'=>404,'msg'=>'没有访问权限，token不合法']);
        }

        return $next($request);
    }
}